package com.hualan.sfzy.controller.counselor;


import com.hualan.sfzy.entity.counselor.CounselorEvaluation;
import com.hualan.sfzy.service.counselor.CounselorEvaluationService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CounselorEvaluationController {
    @Autowired
    private CounselorEvaluationService counselorEvaluationService;

    @PostMapping("/counselorEvaluation")
    public Result add(@RequestBody CounselorEvaluation counselorEvaluation){
        int num = counselorEvaluationService.add(counselorEvaluation);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorEvaluation/{id}")
    public Result remove(@PathVariable Integer id){
        int num = counselorEvaluationService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/counselorEvaluation")
    public Result removeBatch(Integer[] ids){
        int num = counselorEvaluationService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    @PutMapping("/counselorEvaluation")
    public Result edit(@RequestBody CounselorEvaluation counselorEvaluation){
        int num = counselorEvaluationService.edit(counselorEvaluation);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/counselorEvaluation/{id}")
    public Result findById(@PathVariable Integer id){
        CounselorEvaluation counselorEvaluation = counselorEvaluationService.findById(id);
        return Result.success(counselorEvaluation);
    }

    @GetMapping("/counselorEvaluation/page")
    public Result findByPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize,
                                         CounselorEvaluation counselorEvaluation) {
        Map<String, Object> map = counselorEvaluationService.findByPage(pageNum, pageSize, counselorEvaluation);

        return Result.success(map);
    }

    @GetMapping("/counselorEvaluation")
    public Result find(){
        List<CounselorEvaluation> list = counselorEvaluationService.find();
        return Result.success(list);
    }
}
